package L01;
//进程终止
//sleep方法会在抛出异常的同时，清除掉标志位    这样使设置标志位的操作没有生效，线程无法中断
public class T09 {
    public static void main (String[] args) {
        Thread t=new Thread (()->{
            //Thread类内部有关于线程是否结束的标志位
            while(!Thread.currentThread ().isInterrupted ()){
                System.out.println ("线程工作中");
                try {
                    Thread.sleep (2000);
                } catch (InterruptedException e) {
                    //1.假装没听见，线程继续执行
                    e.printStackTrace ();
                    //2.加上break，令线程终止执行
                    break;
                }
            }
        });


        t.start ();
        try {
            Thread.sleep (2000);
        } catch (InterruptedException e) {
            throw new RuntimeException (e);
        }
        System.out.println ("进程终止");
        t.interrupt ();
    }

}
